<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>挂号信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="../../css/font.css">
    <link rel="stylesheet" href="../../css/xadmin.css">
    <link rel="stylesheet" href="../../lib/layui/css/layui.css">
    <script src="../../js/common.js"></script>
    <script src="../../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../js/xadmin.js"></script>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">

                    <div class="x-nav">
			<span class="layui-breadcrumb">
				<a href="">首页</a>
				<a>
					<cite>挂号管理 / Register</cite></a>
			</span>

                        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
                           onclick="location.reload()"
                           title="刷新">
                            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
                    </div>

                    <!-- 挂号添加患者 -->
                    <button class="layui-btn" onclick="xadmin.open('挂号','1.1add.html',600,600)"><i
                            class="layui-icon"></i>挂号
                    </button>
                    <button class="layui-btn layui-btn-danger" id="delAll"><i class="layui-icon"></i>批量删除
                    </button>
                </div>
                <!-- 挂号信息的模糊查询 -->
                </br>
                </br>
                </br>

                <form class="layui-form layui-col-space5" autocomplete="off">
                    <label class="layui-form-label">日期范围</label>
                    <div class="layui-input-inline">
                        <input type="text" name="time" class="layui-input" id="test6" placeholder=" - ">
                    </div>
                    &nbsp;
                    <div class="layui-inline layui-show-xs-block">
                        <input type="text" name="doctorName" placeholder="医生姓名" autocomplete="off" class="layui-input">
                    </div>
                    &nbsp;
                    <div class="layui-inline layui-show-xs-block">
                        <input type="text" name="pName2" placeholder="患者姓名" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-inline layui-show-xs-block">
                        <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i>
                        </button>
                    </div>
                </form>
                <table class="layui-hide" id="test" lay-filter="test"></table>
                <div id="demo7"></div>
            </div>
        </div>
    </div>
</div>
</body>
<script src="../../js/common.js"></script>
<!--数据表格操作按钮-->
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">取消挂号</a>
</script>
<!--时间设置-->
<script>
    layui.use(['laydate', 'form', 'table'], function () {
        var laydate = layui.laydate;
        var form = layui.form;
        var table = layui.table;

        //日期范围
        laydate.render({
            elem: '#test6'
            , range: true
        });

        //监听提交
        form.on('submit(sreach)', function (data) {
            console.log(data.field);
            table.reload('test', {
                url: '/JT90/selectAllRegister',
                where: {
                    time: data.field.time,
                    doctorName: data.field.doctorName,
                    pName2: data.field.pName2,
                }
                , page: {
                    curr: 1
                }
            })
            return false;
        });

    });
</script>
<!--数据表格-->
<script>
    layui.use(['table', 'laypage'], function () {
        var table = layui.table
            , laypage = layui.laypage;

        table.render({
            elem: '#test'
            , url: '/JT90/selectAllRegister'
            , title: '用户数据表'
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'registrationNumber', title: '挂号单号'}
                , {field: 'rDiagnosisNum', title: '诊号'}
                , {field: 'pName2', title: '姓名', }
                , {field: 'pAge2', title: '年龄', }
                , {field: 'pPhone2', title: '手机号码', }
                , {field: 'rDepartment2', title: '挂号科室'}
                , {field: 'doctorName', title: '挂号医生', }
                , {field: 'rVisit2', title: '初/复诊',}
                , {field: 'rRemarks', title: '备注',}
                , {fixed: 'right', title: '操作', toolbar: '#barDemo'}
            ]]
            , response: {
                dataName: 'result' //规定数据列表的字段名称，默认：data   表示这是要解析的参数
            }
            , page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'] //自定义分页布局
                , groups: 5 //只显示 1 个连续页码
                , first: false //不显示首页
                , last: false //不显示尾页
                , limit: 5
                , limits: [5, 10, 15, 20]
                , theme: '#44cc33'
            }
        });


        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;    //获取当前行的数据，有查询id，所以可以获取rId
            if (obj.event === 'del') {
                layer.confirm('确定要取消该挂号单吗', function (index) {
                    useAjax("/JT90/delRegister", {id: data.rId}, "JSON", "GET", function (map) {
                        if (map.success) {
                            parent.layer.msg("取消成功",{time:1500,icon: 6}, function () {
                                //重新加载父页面
                                location.reload();
                            });
                            return;
                        } else {
                            layer.msg("取消失败", {icon: 5});
                        }
                    })
                });
            }
        });

        //批量删除
        $("#delAll").click(function () {
            var checkStatus = table.checkStatus('test'),
                data = checkStatus.data;
            var ids = "";
            if (data.length > 0) {
                for (var i in data) {
                    ids += data[i].rId + ",";
                }
                layer.confirm('确定取消所选的挂号单？', {icon: 3, title: '提示信息'}, function (index) {
                    useAjax("/JT90/delRegisters", {id: ids}, "JSON", "GET", function (map) {
                        layer.close(index);
                        layer.msg("成功取消", {icon: 6});
                        if (map.success) {
                            table.reload('test', {
                                url: '/JT90/selectAllRegister'
                            })
                        } else {
                            layer.msg("取消失败", {icon: 5});
                        }
                    })
                })
            } else {
                layer.msg("请选择挂号单");
            }
        });

        //监听单元格编辑——修改
        table.on('edit(test)', function (obj) {
            var value = obj.value //得到修改后的值
                , data = obj.data //得到所在行所有键值
                , field = obj.field; //修改的数据的字段名

            //由于Register里有对象，传输的时候对象为空会出现异常，这里把传输数据拿出来
            var data1 = {
                "rId": data.rId, "rRemarks": data.rRemarks,
                "doctorName": data.doctorName, "rDepartment2": data.rDepartment2,
                "rVisit2": data.rVisit2, "pName2": data.pName2, "pAge2": data.pAge2, "pPhone2": data.pPhone2
            }
            console.log(data1);
            useAjax("/JT90/UpdateR_P", data1, "JSON", "GET", function (map) {
                if (map.success) {
                    if (field=="pName2"){
                        layer.msg( ' 患者姓名修改为：' + value, {icon: 6});
                    }else if (field=="pAge2"){
                        layer.msg( ' 患者年龄修改为：' + value, {icon: 6});
                    }else if (field=="pPhome2"){
                        layer.msg( ' 患者电话修改为：' + value, {icon: 6});
                    }else if (field=="doctorName"){
                        layer.msg( ' 诊治医生姓名修改为：' + value, {icon: 6});
                    }else if (field=="rDepartment2"){
                        layer.msg( ' 备注修改为：' + value, {icon: 6});
                    }

                    //重载表格
                    table.reload('test', {
                        url: '/JT90/selectAllRegister'
                    })
                } else {
                    layer.msg("修改失败", {icon: 5});
                }
            })

        });
    });
</script>
</html>